<template>
	<view class="content">
		<view v-if="notices.length>0">
			<view bindtap="navRickText(item)" class="list_i" v-for="item in notices">
				<view class="list_ii">{{item.publishTime.replace(/T/," ").split(".")[0]}}</view>
				<view class="list_ick" @click="navContent(item)">
					<view class="title">{{item.title}}</view>
					<view style="margin-top:20upx;">
						<image :src="item.coverImageUrl || noPhoto" mode="aspectFit" class="img_box"></image>
					</view>
					<!-- 		    <view class="list_il"> {{item.title}}</view> -->
				</view>
			</view>
		</view>
		<view class="empty" v-if="notices.length===0">
			<view mode="widthFix" class="noce">
				<text>——暂无信息——</text>
			</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
		<view style="height: 50upx;"></view>

	</view>
</template>

<script>
	import uniBadge from "@/components/uni-badge/uni-badge.vue";
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			uniBadge
		},
		data() {
			return {
				communityId: this.$api.util.getAreaCode(),
				notices: [],
				noPhoto: "https://cdjjyl.com.cn/images/noPhoto.png",
				page: 0,
				loadingType: "more",
			}
		},
		onReachBottom() {
			if (this.loadingType === 'more') {
				this.page = this.page + 1;
				this.inquiryArticle(this.page)
			}
		},
		onLoad(options) {
			this.inquiryArticle(0);
		},
		computed: {
			...mapState(['hasLogin', 'userInfo', 'footPrint'])
		},
		methods: {
			//查询公告活动
			inquiryArticle: function(page) {
				let that = this;
				this.$api.request.articleList({
					areaCode: this.communityId ? this.communityId : "1000000000000000",
					articleType: "5",
					startIndex: page * 4,
					pageSize: 4
				}, function(res) {
					if (res.body.status.statusCode === '0') {
						var articleList = res.body.data.articles;
						for (var i = 0; i < articleList.length; i++) {
							if (articleList[i].articleType == 5) {
								that.notices.push(articleList[i]);
								console.log(that.notices);
							}
						}
						var total = res.body.data.totalCount
						if (that.notices.length >= total) {
							that.loadingType = 'noMore'
						}
					}
				})
			},
			navContent(item) {
				let item1 = encodeURIComponent(JSON.stringify(item));
				if (item.linkType === '自定义内容')
					uni.navigateTo({
						url: '/package_biz/pages/content/richText?item=' + item1
					})
				else if (item.linkType === '外部链接')
					uni.navigateTo({
						url: '/package_biz/pages/content/webView?src=' + item.content
					})
				//已读
				this.markRead(item.articleUuid);
			},
			markRead(articleUuid) {
				var readNotice = uni.getStorageSync('readNotice');
				if (!readNotice) {
					readNotice = [];
				}
				var flag = false; //已读列表是否已经存在该通知
				for (var key in readNotice) {
					if (readNotice[key] == articleUuid) {
						flag = true;
					}
				}
				if (!flag) {
					readNotice.push(articleUuid);
				}
				uni.setStorageSync('readNotice', readNotice);
			}
		}
	}
</script>

<style lang='scss'>
	page {
		width: 100%;
		height: 100%;
		background-color: $page-color-base;
	}

	.empty {
		margin-top: 40upx;
		text-align: center;
		color: $font-color-light;
		font-size: $font-base;
	}

	.list_i {
		border-radius: 10px;
		border-radius: 20upx;
		margin: 8upx 30upx 16upx 30upx;
	}

	.list_ii {
		display: inline-block;
		width: 100%;
		border-radius: 5px;
		text-align: center;
		font-size: 24upx;
		color: rgb(192, 192, 192);
		/* margin-top: 8px; */
		margin-bottom: 16upx;
	}

	.opp {
		font-size: 15px;
		color: #999999;
		text-align: center;
		padding-top: 15px;
	}

	.list_ick {
		font-size: $font-lg;
		color: $font-color-dark;
		background-color: #fff;
		padding: 20upx;
		border-radius: 20upx;
	}

	.list_il {
		font-size: $font-base;
		color: $font-color-light;
		margin-top: 20upx;
	}

	.img_box {
		width: 100%;
		height: 400upx;
	}

	.title {
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
	}
</style>
